package com.w.proxy.proxy.cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;


/**
 * CGLIB 动态代理
 *
 */
public class CglibProxy implements MethodInterceptor {

    private static volatile CglibProxy instance;

    private CglibProxy() {

    }

    public static CglibProxy getInstance() {
        if (null == instance) {
            synchronized (CglibProxy.class) {
                if (null == instance) {
                    instance = new CglibProxy();
                }
            }
        }
        return instance;
    }

    public <T> T getProxy(Class<T> cls) {
        return (T) Enhancer.create(cls, this);
    }


    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        return null;
    }
}
